﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using Services;
using MvcPaging;
using EntityModel;
namespace ShopWeb.Controllers
{
    public class CategoryController : Controller
    {
        #region 公用属性
        private CategoryService categoryService = new CategoryService();
        private ProductService productService = new ProductService();
        private int pageSize = ConfigHelper.PageSize();
        #endregion


        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Detail(int cid = 0, int? page = 0)
        {
            int PageIndex = page.HasValue ? (page.Value == 0 ? 0 : (page.Value - 1)) : 0;
            //var list = productService.GetListByCategoryId(cid).ToPagedList(PageIndex, pageSize);
            var list = productService.GetAllPruductById(cid).ToPagedList(PageIndex, pageSize);
            Category c = categoryService.GetModel(cid);
            ViewData["SeoTitle"] = c.Name;
            ViewData["MetaKeywords"] = c.MetaKeywords;
            ViewData["MetaDescription"]=c.MetaDescription;
            ViewData["CategoryId"] = c.Id;
          //  ViewData["list"]=list;
            return View(list);
        }

    }
}
